package app.fugema.shop.main.goods.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import com.base.common.utils.DensityUtil;
import com.base.common.utils.OnClickCheckedUtil;
import com.base.common.view.base.BaseActivity;
import com.base.common.view.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import app.fugema.shop.R;
import app.fugema.shop.databinding.ActivityShopBinding;

import app.fugema.shop.main.goods.vm.GoodsVM;


public class ShopActivity extends BaseActivity<ActivityShopBinding, GoodsVM>
{

    public static void start(Context context, int shopId)
    {
        Intent intent = new Intent(context, ShopActivity.class);
        intent.putExtra("shopId", shopId);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop);
    }

    @Override
    protected int getStatusBarColor()
    {
        return R.color.redColor;
    }

    //微店id
    private int shopId;

    private List<BaseFragment> list = new ArrayList<>();
    @Override
    protected void initView()
    {
        super.initView();
        //setCloseImg(R.mipmap.ic_back_white);
        //setTitle("店铺详情" , R.color.white);
        int statusBarH = DensityUtil.getStatusBarHeight(getActivity());
        ViewGroup.LayoutParams layoutParams = (ViewGroup.LayoutParams) binding.statusBar.getLayoutParams();
        layoutParams.height = layoutParams.height + statusBarH;
        binding.statusBar.setLayoutParams( layoutParams );
        binding.ivBack.setOnClickListener(new OnClickCheckedUtil() {
            @Override
            public void onClicked(View view) {
                finish();
            }
        });
    }


    @Override
    protected void initData(Intent intent)
    {
        super.initData(intent);
        shopId = intent.getIntExtra("shopId", 0);
        ShopMiniFragment shopMiniFragment = ShopMiniFragment.getInstance(shopId);
        list.add(shopMiniFragment);
        ShopAllGoodsFragment allGoodsFragment = ShopAllGoodsFragment.getInstance(shopId);
        list.add(allGoodsFragment);

        binding.vpPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return list.get(position);
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return list.get(position).getTitle();
            }

            @Override
            public int getCount() {
                return list.size();
            }
        });

        viewUtils.initSlidingTabLayout(binding.stlTab, binding.vpPager,new String[]{"推荐","宝贝"});

    }


}
